package com.zjxf.resource.properties;

import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.zjxf.base.common.SysConst;
import com.zjxf.utils.HttpClientUtils;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * created with IntelliJ IDEA
 *
 * @author: create by limu
 * Date: 2019/11/21
 * Time：11:50
 */
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "customer.resource-manager")
public class ResourceMangerProperties {

    private String host;

    private String fixedUrl;    //注: 全地址

    private RSA rsa = new RSA();

    @Getter
    @Setter
    public static class RSA {
        private String privateKey;
        private String publicKey;
        private String prefix;
        private String suffix;
    }

    /**
     * 获取真实远程请求地址 注: 如配置host则为固定线上ip地址
     * 示例:
     *
     * @return 文件服务器真实地址
     */
    public String getRemoteHost() {
        if (StringUtils.isBlank(host)) {
            String resultStr = HttpClientUtils.getInstance().httpGet(SysConst.IP_SERVER, Maps.newHashMap());
            JSONObject resultObj = JSONObject.parseObject(resultStr);
            return resultObj.getString("data");
        } else {
            return host;
        }
    }
}
